import 'dart:io';

import 'package:flutter/services.dart';

class AndroidChannel {
  static const _batteryChannelName = "app.channel.shared.data";  // 1.方法通道名称
  static late MethodChannel _batteryChannel;

  static void initChannels(){
    _batteryChannel = const MethodChannel(_batteryChannelName);  // 2. 实例化一个方法通道
  }

  // 3. 异步任务，通过平台通道与特定平台进行通信，这里的宿主平台是 Android
  static Future<String> printHandler(dynamic param) async {
    String log;
    try {
      await _batteryChannel.invokeMethod('printerHandler_flow', param);
      log = '打印成功';
    } on PlatformException catch (e) {
      log = "打印失败";
    }
    return log;
  }

  ///外协接收分支
  static Future<String> printInbound(dynamic param) async {
    String log;
    try {
      await _batteryChannel.invokeMethod('printInbound_flow', param);
      log = '打印成功';
    } on PlatformException catch (e) {
      log = "打印失败";
    }
    return log;
  }

  ///工序周转分支
  static Future<String> printTakeHandler(dynamic param) async {
    String log;
    try {
      await _batteryChannel.invokeMethod('printerTake_flow', param);
      log = '打印成功';
    } on PlatformException catch (e) {
      log = "打印失败";
    }
    return log;
  }

  /// 重启app
  static void restartApp() async{
    try {
      await _batteryChannel.invokeMethod('restartApp');
      print("success");
    } on PlatformException catch (e) {
      print("error${e}");
    }
  }

}